<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/6 12:21
 */

namespace module\ai\library\channel\platform;

use module\ai\library\channel\abstract\Platform;
use mof\Model;

class BaiduPlatform extends Platform
{
    protected string $regUrl = 'https://qianfan.cloud.baidu.com/';

    public static function getName(): string
    {
        return '文心一言';
    }

    public static function getFlag(): string
    {
        return 'baidu';
    }

    public static function models(): array
    {
        return [
            'completions'         => 'ERNIE-3.5-8K',
            'ernie-3.5-128k'      => 'ERNIE-3.5-128K',
            'completions_pro'     => 'ERNIE-4.0-8K',
            'ernie-4.0-turbo-8k'  => 'ERNIE-4.0-Turbo-8K(旗舰级)',
            'ernie-4.0-8k-latest' => 'ERNIE-4.0-8K-Latest(旗舰级)',
            'ernie-tiny-8k'       => 'ERNIE-Tiny-8K',
            'ernie-lite-8k'       => 'ERNIE-Lite-8K',
            'ernie_speed'         => 'ERNIE-Speed-8K',
            'ernie-speed-128k'    => 'ERNIE-Speed-128K',
            'ernie-char-8k'       => 'ERNIE-Character-8K(角色扮演)',
            'ernie-novel-8k'      => 'ERNIE-Novel-8K(小说续写)',
        ];
    }

    public function getConfigForm(Model $model = null): array
    {
        return [
            ...parent::getConfigForm($model),
            [
                "label" => "temperature",
                "prop"  => "config.temperature",
                "value" => $model['config']['temperature'] ?? '',
                "intro" => "温度，较高的数值会使输出更加随机，而较低的数值会使其更加集中和确定。取值范围[0.01, 1.00]。建议该参数和top_p只设置1个。",
                "tip"   => "",
            ],
            [
                "label" => "top_p",
                "prop"  => "config.top_p",
                "value" => $model['config']['top_p'] ?? '',
                "intro" => "多样性，影响输出文本的多样性，取值越大，生成文本的多样性越强。取值范围[0, 1.0]。建议该参数和temperature只设置1个。"
            ],
            [
                "label" => "penalty_score",
                "prop"  => "config.penalty_score",
                "value" => $model['config']['top_k'] ?? '',
                "intro" => "重复惩罚，用通过对已生成的token增加惩罚，减少重复生成的现象。说明：值越大表示惩罚越大。取值范围[1.0, 2.0]。"
            ],
            [
                "label" => "max_output_tokens",
                "prop"  => "config.penalty_score",
                "value" => $model['config']['top_k'] ?? '',
                "intro" => "模型最大输出token数，说明：如果设置此参数，范围[2, 4096]，如果不设置此参数，最大输出token数为1024。"
            ],
        ];
    }
}